import java.io.*;
import java.net.*;
import java.util.*;
import java.util.stream.Collectors;


/**
 * Created by zyl on 17-6-1.
 */
public class Client1 {
    public static void main(String args[]) {

        MyBC receiver = new MyBC();

        try {
            Socket socket = new Socket("192.168.199.205", 3500);
//鍚戞湰鏈虹殑3500绔彛鍙戝嚭瀹㈡埛璇锋±??

            BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
//鐢辩郴缁熸爣鍑嗚緭鍏ヨå¬鏋勯??燘ufferedReader瀵硅薄

            PrintWriter os = new PrintWriter(socket.getOutputStream());
//鐢盨ocket瀵硅薄寰楀埌杈撳嚭娴侊紝骞舵瀯閫燩rintWriter瀵硅±??

            BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//鐢盨ocket瀵硅薄寰楀埌杈撳叆娴侊紝骞舵瀯閫犵浉搴旂殑BufferedReader瀵硅薄


            String readline;

            readline =sin.readLine();
            //浠庣郴缁熸爣鍑杈撳叆璇诲叆涓??瀛楃涓??


            while (!readline.equals("bye")) {
//鑻ヤ粠鏍囧噯杈撳叆璇诲ョ殑瀛楃涓蹭负 "bye"鍒欏仠姝㈠惊鐜??


                os.println( receiver.exchangexpr (readline));
                /*鎶婁腑缂??琛ㄨ揪寮忚皟鐢∕yBC.java鐨勫姛鑳借浆鍖栦负鍚庣紑琛ㄨ揪寮忥紝鎶婂庣紑琛ㄨ揪寮忛??氳繃缃戠粶鍙戦??佺粰鏈嶅姟å*/

                //灏嗕粠绯荤粺鏍囧噯杈撳叆è°鍏ョ殑瀛楃涓茶緭鍑哄埌Server

               os.flush();

                //鍒锋柊杈撳嚭娴侊紝浣¿Server椹笂鏀跺埌璇ュ瓧绗︿覆

                System.out.println("Client:" + readline);

                //鍦ㄧ郴缁熸爣鍑嗚緭鍑轰笂鎵撳嵃璇诲叆鐨勫瓧绗︿覆

                System.out.println("Server:" + is.readLine());

                //浠嶴erver璇诲叆涓??瀛楃涓诧紝骞舵墦鍗板埌鏍囧噯杈撳嚭涓??

                readline = sin.readLine(); //浠庣郴缁熸爣鍑嗚緭鍏ヨ鍏ヤ竴瀛楃涓??


            } //缁х画寰ª鐜??

            os.close(); //鍏抽棴Socket杈撳嚭娴??

            is.close(); //鍏抽棴Socket杈撳叆娴??

            socket.close(); //鍏抽棴Socket

        } catch (Exception e) {
            System.out.println("Error" + e); //鍑洪敊锛屽垯鎵撳嵃鍑洪敊淇℃伅

        }
    }
}

